<template>
  <el-container id="home">
    <el-header>
      <div class="img_box">
        <!--logo 和 网站名称-->
        <img
            src="@/assets/guigu.jpeg"
            alt=""
            style="width: 50px; height: 50px"
        />
        <span>硅谷后台管理系统</span>
      </div>
      <!--退出按钮-->
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!--<el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">-->
        <!--  <el-radio-button :label="false">展开</el-radio-button>-->
        <!--  <el-radio-button :label="true">收起</el-radio-button>-->
        <!--</el-radio-group>-->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu :router="true" default-active="1-4-1" class="el-menu-vertical-demo"
                 active-text-color="orange"
                 @open="handleOpen" @close="handleClose" :collapse="isCollapse"
                 :collapse-transition="false">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">示例</span>
            </template>
            <el-submenu index="1-1">
              <span slot="title">Upload上传</span>
              <el-menu-item index="/upload_demo1">用户头像上传</el-menu-item>
            </el-submenu>
            <el-submenu index="1-2">
              <span slot="title">卡片</span>
              <el-menu-item index="/card_demo1">带图片的卡片</el-menu-item>
            </el-submenu>
            <el-submenu index="1-3">
              <span slot="title">表格</span>
              <el-menu-item index="/table_demo1">基础表格</el-menu-item>
            </el-submenu>
            <el-submenu index="1-4">
              <span slot="title">级联组件</span>
              <el-menu-item index="/cascade_demo1">省市级联</el-menu-item>
              <el-menu-item index="/cascade_demo2">级联面板</el-menu-item>
              <el-menu-item index="/cascade_demo3">无限级分类(递归)</el-menu-item>
              <el-menu-item index="/cascade_demo4">无限级分类(非递归)</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">状态管理</span>
            </template>
            <el-submenu index="2-1">
              <span slot="title">Vuex</span>
              <el-menu-item index="/vuex_demo1">演示1</el-menu-item>
              <el-menu-item index="/vuex_test">测试</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">第三方常用插件</span>
            </template>
            <el-submenu index="3-1">
              <span slot="title">百度地图API</span>
              <el-menu-item index="/map_demo1">静态获取浏览器当前定位</el-menu-item>
              <el-menu-item index="/map_demo2">动态获取浏览器当前定位</el-menu-item>
            </el-submenu>
            <el-submenu index="3-2">
              <span slot="title">Echarts图表API</span>
              <el-menu-item index="/echarts_demo1">简单图表</el-menu-item>
            </el-submenu>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export  default {
  data() {
    return {
      isCollapse: false
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },// 退出
    logout() {
      // 清空sessionStorage
      window.sessionStorage.clear();
      // 退回到登录页，路由跳转
      this.$router.push("/login");
    },// 控制菜单展开和折叠
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
  }
}
</script>

<style scoped>
#home{
  height: 100%;
}

/* toggle-button */
.toggle-button{
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.5em;
}

.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
  /*
  在flex 布局的容器中，
  可以设置justify-content: space-between;实现两对齐
  */
  display: flex;
  justify-content: space-between;
  /* 当容器是flext，可以设置 align-items: center */
  align-items: center;
  div {
    display: flex;
    align-items: center;
  }
  span {
    margin-left: 20px;
  }
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {

}

.el-container:nth-child(7) .el-aside {

}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
